//
//  QHHCPInternalPreferences.m
//  QHealthForDoctor
//
//  Created by 李志良的mac mini on 2020/4/13.
//  Copyright © 2020 李 志良. All rights reserved.
//

#import "QHHCPInternalPreferences.h"
#import "NSUserDefaults+RMSaveCustomObject.h"

static NSString *const PLUGIN_CONFIG_USER_DEFAULTS_KEY = @"plugin_config";

@implementation QHHCPInternalPreferences

+ (QHHCPInternalPreferences *)loadFromUserDefaultsWithFolderName:(NSString*)folderName{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    id instance = [userDefaults rm_customObjectForKey:[NSString stringWithFormat:@"%@%@",PLUGIN_CONFIG_USER_DEFAULTS_KEY,folderName]];
    if (instance) {
        return instance;
    }else{
        NSDictionary * bundleChcpJson = [QHHCPConfig configFromBundle:folderName fileName:@"chcp.json"];
        QHHCPInternalPreferences * tempInstance = [[QHHCPInternalPreferences alloc]init];
        tempInstance.currentReleaseVersionName = bundleChcpJson[@"release"];
        return tempInstance;
    }
    
}

-(void)savePreferenceToLocalWithFolderName:(NSString*)wwwFoldername{
    [[NSUserDefaults standardUserDefaults] rm_setCustomObject:self forKey:[NSString stringWithFormat:@"%@%@",PLUGIN_CONFIG_USER_DEFAULTS_KEY,wwwFoldername]];
}


@end
